$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'quoteConfig/quoteconfigvalue/list',
        datatype: "json",
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', width:80, key: true ,hidden: true},
			{ label: '常量键值', name: 'configKey', index: 'config_key', width: 80 }, 			
			{ label: '常量类型', name: 'configType', index: 'config_type', width: 80},
			{ label: '参数值', name: 'configValue', index: 'config_value', width: 80 }, 			
			{ label: '描述', name: 'configDesc', index: 'config_desc', width: 80 }, 			
			{ label: '是否屏蔽', name: 'delFlag', index: 'del_flag', width: 80,align:'center',
                formatter: function (value) {
                   return value?"是":"否"
                }
			},
			{ label: '是否在前端显示', name: 'display', index: 'display', width: 80,align:'center',
                formatter: function (value) {
                    return value?"是":"否"
                }
			},
			{ label: '创建时间', name: 'createDate', index: 'create_date', width: 80 }, 			
			{ label: '创建人员', name: 'createUser', index: 'create_user', width: 80 }, 			
			{ label: '更新时间', name: 'updateDate', index: 'update_date', width: 80 }, 			
			{ label: '更新人员', name: 'updateUser', index: 'update_user', width: 80 },
            { label: '操作', name: 'operation',  width: 60 , align:'center',title:false,
                formatter:function(value, options, row){
                    var html = '<li class="dropdown" style="list-style: none;position: absolute;width: 60px;right: auto;left: auto;"><a href="#" style="margin:0 auto;text-decoration:none;" class="dropdown-toggle" data-toggle="dropdown">操作</a>';
                    html += '<ul class="dropdown-menu"  style="min-width:100%;font-size: 12px;">';
                    var operations = [];
                    //console.log(row);
                    operations.push('<li><a href="javascript:;" onclick="vm.updateConfig('+row.id+');">修改</a></li><li class="divider"></li>');
                    operations.push('<li><a href="javascript:;" onclick="vm.delConfig('+row.id+');">删除</a></li><li class="divider"></li>');
                    html += operations.join("")
                    html += '</ul></li>';
                    return html;
                }
            }
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 40,
        autowidth:true,
        multiselect: false,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount",
            userdata: "userData"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
            vm.e.quoteConfigEnum = $("#jqGrid").jqGrid('getGridParam', 'userData').quoteConfigEnum;
        }
    });
    // 显示序号
    $("#jqGrid").jqGrid('setLabel',0, '序号', '{width:80}');
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		quoteConfigValue: {},
        /* 查询 */
        q:{
            configKey: '',
            configValue: '',
            configDesc:'',
        },
        e: {
            quoteConfigEnum: []
        }
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.quoteConfigValue = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			alert(id);
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
        updateConfig: function (id) {
            vm.showList = false;
            vm.title = "修改";

            vm.getInfo(id)
        },
		saveOrUpdate: function (event) {
			var url = vm.quoteConfigValue.id == null ? "quoteConfig/quoteconfigvalue/save" : "quoteConfig/quoteconfigvalue/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.quoteConfigValue),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "quoteConfig/quoteconfigvalue/delete",
                    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
        delConfig: function (id) {
            confirm('确定要删除选中的记录？', function(){
                $.ajax({
                    type: "POST",
                    url: baseURL + "quoteConfig/quoteconfigvalue/delete/"+id,
                    contentType: "application/json",
                    success: function(r){
                        if(r.code == 0){
                            alert('操作成功', function(index){
                                $("#jqGrid").trigger("reloadGrid");
                            });
                        }else{
                            alert(r.msg);
                        }
                    }
                });
            });
        },


		getInfo: function(id){
			$.get(baseURL + "quoteConfig/quoteconfigvalue/info/"+id, function(r){
                vm.quoteConfigValue = r.quoteConfigValue;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page,
                postData:{//postData此数组内容直接赋值到url上，参数类型：{name1:value1…}
                    'configKey': vm.q.configKey.trim(),
                    'configValue': vm.q.configValue.trim(),
					'configDesc':vm.q.configDesc.trim(),
                },
            }).trigger("reloadGrid");
		},
        reset: function (event) {
            vm.q.configKey = '';
            vm.q.configValue = '';
            vm.q.configDesc = '';
            vm.reload();
        },
	},
});